package com.qsl.ssyx.product.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.model.product.AttrGroup;
import com.qsl.ssyx.product.service.AttrGroupService;
import com.qsl.ssyx.vo.product.AttrGroupQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 属性分组 前端控制器
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-10
 */
@Api(tags = "平台属性分组接口")
@RestController
@RequestMapping("/admin/product/attrGroup")
public class AttrGroupController {


    @Autowired
    private AttrGroupService attrGroupService;

    @ApiOperation("条件分页查询")
    @GetMapping("{page}/{limit}")
    public Result selectPage(@ApiParam(value = "当前页") @PathVariable Integer page
            , @ApiParam(value = "每页记录数") @PathVariable Integer limit
            , AttrGroupQueryVo attrGroupQueryVo) {
        Page<AttrGroup> pageParam = new Page<>(page, limit);
        IPage<AttrGroup> model = attrGroupService.selectPage(pageParam, attrGroupQueryVo);
        return Result.ok(model);
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(@RequestBody AttrGroup attrGroup) {
        boolean flag = attrGroupService.save(attrGroup);

        return Result.ok(flag);
    }

    @ApiOperation("根据Id查询")
    @GetMapping("getById/{id}")
    public Result save(@ApiParam(value = "id") @PathVariable("id") Integer Id) {
        AttrGroup attrGroup = attrGroupService.getById(Id);
        return Result.ok(attrGroup);
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody AttrGroup attrGroup) {
        boolean flag = attrGroupService.updateById(attrGroup);
        return Result.ok(flag);
    }

    @ApiOperation("删除")
    @DeleteMapping("remove/{Id}")
    public Result remove(@PathVariable Integer Id) {
        boolean flag = attrGroupService.removeById(Id);
        return Result.ok(flag);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Integer> idList) {
        boolean flag = attrGroupService.removeByIds(idList);
        return Result.ok(idList);
    }

    @ApiOperation("查询所有平台属性分组")
    @GetMapping("findAllList")
    public Result findAllList() {
        List<AttrGroup> attrGroup = attrGroupService.findAllList();
        return Result.ok(attrGroup);
    }
}

